pp108 : Sprintf Function for Formatting Generic Data

Sprintf Function for Formatting Generic Data

This topic describes the sprintf function for formatting generic data.


You can use the sprintf function to customize generic data to produce the output in any form such as figures, digits, exponential form, numeric representation in non-decimal form, and so on.

The following table lists the formats supported by the sprintf function for formatting generic data:

Table 1. Sprintf Function for Formatting Generic Data

Format

Description

%d, %I

Signed integer values

%e

Doubles with exponent, with 2 or 3 positions for exponent. For example: 1.23e+02

%E

Similar to e. For example, 1.23E+02

%f

Doubles to 6 decimal places. For example, 32.123456

%g

Double values; %e or %g, whichever is more compact, is used

%G

Double values; %E or %g, whichever is more compact, is used

%s

Strings

%o

Octal representation of unsigned integers

%x

Hexadecimal representation of unsigned integers. For example, 374fff

%X

Hexadecimal representation using uppercase for A-F. For example, 374FFF

%XD

Date format that uses XML string as input

%XT

Time format that uses XML string as input

%u

Unsigned integer

%l

The locale



Note: The locale,
%l, cannot be specified in conjunction with other formats. Once you set the locale, all subsequent formatting for date, time, and currency values will be in that locale only. Therefore, locale must be installed on your system. Otherwise, the default posix notation (for example, en_US, nl_NL) is used by the system.